package com.briansteen.painterface;

import java.awt.BasicStroke;
import java.awt.Color;
import java.awt.Graphics2D;

import cc.creativecomputing.graphics.CCGraphics;

public class ColorParticle {
	public float oldX;
	public float oldY;
	public float currX;
	public float currY;
	private Color color;
	private float transparency;
	private float dtransparency;
	public float gravity;
	public float drag;
	public float lineWeight;
	public boolean isFinished = false;
	private boolean isWet;
	public float red = .8f;
	public float blue = 0;
	public float green = 0;
	public boolean wander = false;
	private int Count = 0;
	public ColorParticle(float oldX, float oldY, float currX, float currY,
			Color color, float transparency, float gravity, float drag,
			float lineWeight, boolean isWet) {
		this.oldX = oldX;
		this.oldY = oldY;
		this.currX = currX;
		this.currY = currY;
		this.color = color;
		this.transparency = transparency;
		this.gravity = gravity;
		this.drag = drag;
		this.lineWeight = lineWeight;
		this.isWet = isWet;
	}

	public void draw(CCGraphics g2d) {
		Count++;
		if (!isFinished) {
			BasicStroke stroke = new BasicStroke(lineWeight,BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND);
			float xs = currX - oldX;
			float ys = currY - oldY;
			oldX = currX;
			oldY = currY;
			float speed = (float) Math.sqrt(xs * xs + ys * ys);
			currX += xs * drag;
			currY += (ys + gravity) * drag;
			gravity *= drag;
			// lineWeight *= drag*.01;
			if (dtransparency <= transparency)
				dtransparency += .01f;
			if (isWet) {
				if (speed < 2) {
					/*
					 * container.graphics.lineStyle(lineWeight,color,transparency);
					 * container.graphics.moveTo(oldX, oldY);
					 * container.graphics.lineTo(currX, currY);
					 */
				}
			} else {
				g2d.color(red, green, blue, dtransparency);
				g2d.strokeWeight(lineWeight);
				g2d.line((int) oldX, (int) oldY, (int) currX, (int) currY);
			}

			if (isWet && speed < 5) {
				for (int i = 0; i < 2; i++) {
					float size = lineWeight
							* (i + Count * .5f);
					if(size > 40){
						size = 40;
						isFinished = true;
					}
					float alpha = Count*.001f;// transparency * (.00035f);
					if (alpha < 0) alpha = 0;
					if (alpha > .01f) alpha = .01f;
					
					stroke = new BasicStroke(size,BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND);
					g2d.color(red, green, blue, transparency*.05f);
					g2d.strokeWeight(size);
					g2d.line((int) oldX, (int) oldY, (int) currX, (int) currY);
				}
			}
			if (speed < .01f)
				isFinished = true;
			if(Count > 50) isFinished = true;
		} else {
		}
	}
}
